<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>http-config-add</title>
	<%@ include file="../include/common.jsp"%>
	<%@ include file="../include/form.jsp"%>
	
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery/jquery-ui.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/select/jquery.multiselect.min.js"></script>
	<link rel="stylesheet"  type="text/css" href="${pageContext.request.contextPath}/style/default/select/jquery.multiselect.css" />
	<link rel="stylesheet"  type="text/css" href="${pageContext.request.contextPath}/style/default/jqueryui/jquery-ui.css" />
	
  <script type="text/javascript">
  
  function add(){
	//校验(url+账号)是否唯一
	  
	  $.ajax({
		   type: "POST", 
		   url: "${pageContext.request.contextPath}/config/http-config!valideUrlUserName.action", //请求的action
		   data: "userName="+$("#userName").val()+"&url="+$("#url").val()+"&isValideFlag="+"true", //传的参数
		   dataType: 'json',
		   success: function(data){ //结果
			   if(data == true){
				   //提交
					 $.ajax({
						   type: "POST", 
						   url: "${pageContext.request.contextPath}/config/http-config!save.action", //请求的action
						   data: $("#myform").serialize(), //传的参数
						   dataType: 'json',
						   success: function(data){ //结果
							   if(data == true){
								   var pWin = getTopWin(window).currentWin["add-http-config"];
								   pWin.datagrid();
								
								   getTopWin(window).closejBox("add-http-config");
							   }
							   
						   }
					});
			   }else{
				   getTopWin(window).getMessageBox().alert("url+账号  必须唯一存在","提示");
			   }
		   }
	});
  }
  
  $(function(){
	  $.formValidator.initConfig({formid:"myform"
          ,onerror:function(msg){}
          ,onsuccess:function(){
        	  		add();
          			return false;
          }
          });
	  
	  $("#url").formValidator({onshow:"请输入字符串 长度(1-128)",onfocus:"请输入字符串  长度(1-128)",oncorrect:"输入正确"}).inputValidator({min:1,onerror:"不能为空"}).inputValidator({empty:{leftempty:false,rightempty:false,emptyerror:"两边不能有空格"},onerror:"不能为空"})
	  .functionValidator({
			    fun:function(val,elem){
			    	    if(val.replace(/[^\x00-\xff]/g, "xx").length > 128){
			    	        return "长度超出最大范围";
			    	    }
			    	    return true;
				}
	  });
	  $("#userName").formValidator({onshow:"请输入字符串 长度(1-32)",onfocus:"请输入字符串 长度(1-32)",oncorrect:"输入正确"}).inputValidator({min:1,onerror:"不能为空"}).inputValidator({empty:{leftempty:false,rightempty:false,emptyerror:"两边不能有空格"},onerror:"不能为空"})
	  .functionValidator({
			    fun:function(val,elem){
			    	    if(val.replace(/[^\x00-\xff]/g, "xx").length > 32){
			    	        return "长度超出最大范围";
			    	    }
			    	    return true;
				}
	  });
	  $("#pwd").formValidator({onshow:"请输入字符串 长度(1-32)",onfocus:"请输入字符串 长度(1-32)",oncorrect:""}).inputValidator({empty:{leftempty:false,rightempty:false,emptyerror:"两边不能有空格"},onerror:"不能为空"})
	  .functionValidator({
			    fun:function(val,elem){
			    	    if(val.replace(/[^\x00-\xff]/g, "xx").length > 32){
			    	        return "长度超出最大范围";
			    	    }
			    	    return true;
				}
	  });
	  $("#pwd1").formValidator({onshow:"2次密码要一致",onfocus:"2次密码要一致",oncorrect:""}).compareValidator({desid:"pwd",operateor:"=",onerror:"2次密码不一致"});
  });
  function closewin(){
	   getTopWin(window).closejBox("add-http-config");
  }

  
  </script>
  </head>
  
  <body class="padding-8">
    	<form action="" id="myform" name="myform" method="post">
    		<table  class="table_eidt">
    			<tr>
	    			<td class="td_left" width="80px"><span class="span_alert">*</span>服务URL</td>
	    			<td class="td_right"><input type="text" name="url" id="url" class="input_text">
	    			<span id="urlTip" style="width:150px"></span></td>
    			</tr>
    			<tr>
	    			<td class="td_left"><span class="span_alert">*</span>帐号</td>
	    			<td class="td_right"><input type="text" name="userName" id="userName" class="input_text">
	    			<span id="userNameTip" style="width:150px"></span></td>
    			</tr>
    			<tr>
	    			<td class="td_left">密码</td>
	    			<td class="td_right"><input type="password" name="pwd" id="pwd" class="input_text">
	    			<span id="pwdTip" style="width:150px"></span></td>
    			</tr>
    			<tr>
	    			<td class="td_left">确认密码</td>
	    			<td class="td_right"><input type="password" name="pwd1" id="pwd1" class="input_text">
	    			<span id="pwd1Tip" style="width:150px"></span></td>
    			</tr>
    		</table>
    		<div align="center" style="margin-top:9px;">
	    		<input type="submit" id="button" name="button" value="保存" class="btn-4">
	    		<input type="reset" class="btn-4">
	    		<input type="button" value="取消" onclick="closewin();" class="btn-4">
    		</div>
    	</form>
  </body>
</html>
